<template>
  <div class="contirner" v-if="isShowMain">
    <slot name="nav-bar">
      <NavBar v-if="isShowNavBar"></NavBar>
    </slot>
    <ScrollList @refresh="onRefresh" @load="onLoad" :finshed="finshed">
      <slot></slot>
    </ScrollList>
    <slot name="tab-bar">
      <TabBar v-if="isShowTabbar"></TabBar>
    </slot>
  </div>
  <div class="contirner" v-else>
    <slot></slot>
  </div>

  <!-- <Toast></Toast> -->
  <!-- <Loading></Loading> -->
</template>

<script setup>
import NavBar from '@/plugins/components/NavBar/index.vue';
import TabBar from '@/plugins/components/TabBar/index.vue';
import ScrollList from '@/plugins/components/ScrollList/index.vue';

import { setTabbarIndex } from '@/router/hooks.js';
import { others, navbars, tabbars } from '@/router/index.js';
import { useRoute, useRouter } from 'vue-router';
import { ref, watchEffect } from 'vue';

const route = useRoute();
const router = useRouter();


const props = defineProps({
  finshed: { type: Boolean, default: false },
  navbar: { type: Boolean, default: false },
  tabbar: { type: Boolean, default: false }
});

const emit = defineEmits(['refresh', 'load']);

const isShowMain = ref(true);
watchEffect(() => {
  const index = others.findIndex(_s => _s.path === route.path);
  isShowMain.value = index === -1 ? true : false; 
})

const isShowTabbar = ref(false);
watchEffect(() => {
  const index = tabbars.findIndex(_s => _s.path === route.path);
  if(index !== -1) {
    isShowTabbar.value = true;
    setTabbarIndex( index );
  } else {
    isShowTabbar.value = false;
  }
})

const isShowNavBar = ref(false);
watchEffect(() => {
  const index = navbars.findIndex(_s => _s.path === route.path);
  isShowNavBar.value = index === -1 ? false : true; 
})

//  上拉刷新
const onRefresh = () => {
  emit('refresh');
}

//  下拉加载
const onLoad = () => {
  emit('load');
}
</script>

<style lang="scss" scoped>
.contirner {
  display: flex;
  flex-direction: column;
  height: 100vw;
  height: 100vh;
  overflow: hidden;
  box-sizing: border-box;
}
</style>